/*
 *  $Id: Drowning.cs 1004 2010-05-03 11:50:53Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Water.Spells {
    public class Drowning: SelfEnchantmentCard {
        public Drowning(): base("001_w_s_drowning") {
            Level = CompleteLevel.ReadyForTest;
            Element = ElementType.Water;
            Value = 100;
            AddCondition(new AffectCondition<DrowningAffect>(GetConditionPhrase(), false));
        }

        protected override EnchantmentAffect CreateEnchantment() {
            return new DrowningAffect();
        }

        private class DrowningAffect: EnchantmentAffect<Drowning> {
            private int _count;

            public DrowningAffect(): base(true) {
                DefaultDescription = true;
                Add(new Affects.Immune(DamageType.PhysicalAttack));
                Add(new Affects.AbilityAffect(CardManager.GetAbility<DrowningFinish>()));
            }

            public override bool Dispellable {
                get { return false; }
            }

            public override string DescriptionText {
                get { return Description.GetText(_count); }
            }

            public override void SetAffect() {
                base.SetAffect();
                LocalSummary.OnStartOffencePhase += DoDrowning;
            }
            public override void ResetAffect() {
                base.ResetAffect();
                LocalSummary.OnStartOffencePhase -= DoDrowning;
            }

            private void DoDrowning() {
                _count++;
                UpdateDescription();
                Owner.DamageDirectBy(NewDamage(DamageType.Health, _count), true);
            }
        }

        private class DrowningFinish: AbilityCard {
            public DrowningFinish(): base("001_w_a_drowning_finish") {
                Level = CompleteLevel.ReadyForTest;
                SetPictureSource<Drowning>();
                Element = ElementType.Water;
            }

            public override void DoAction(TargetArgs args) {
                args.Caster.RemoveAffect<DrowningAffect>();
            }
        }
    }
}